package com.xyebank.ledger.service.nx.dataprovider.repay;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.vo.deal.LNxCashRepaymentInfoVo;

@Component
public class NxRepaymentDataProvider implements DataProvider<LNxCashRepaymentInfoVo> {

    @Autowired
    private SNxCashRepaymentMapper mNxCashRepaymentMapper;

    @Override
    public List<LNxCashRepaymentInfoVo> get(Integer fromIdx, Integer tarNum) {
        List<SNxCashRepayment> result = mNxCashRepaymentMapper.selectByPaging(fromIdx, tarNum);
        List<LNxCashRepaymentInfoVo> list = convert2Vo(result);
        return list;
    }


    @Override
    public List<LNxCashRepaymentInfoVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {
        List<SNxCashRepayment> result = mNxCashRepaymentMapper.selectByPeriod(dateStart, dateEnd, fromIdx, tarNum);
        List<LNxCashRepaymentInfoVo> list = convert2Vo(result);
        return list;
    }


    @Override
    public Integer count(Date timeStart, Date timeEnd) {
        Integer count = mNxCashRepaymentMapper.selectPeriodCount(timeStart, timeEnd);
        return count;
    }


    private List<LNxCashRepaymentInfoVo> convert2Vo(List<SNxCashRepayment> result) {
        List<LNxCashRepaymentInfoVo> list = new ArrayList<LNxCashRepaymentInfoVo>();
        for (int i = 0; i < result.size(); i++) {
            LNxCashRepaymentInfoVo vo = new LNxCashRepaymentInfoVo();
            BeanUtils.copyProperties(result.get(i), vo);
            list.add(vo);
        }
        return list;
    }

}
